package com.sanqing.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.sanqing.po.Student;
import com.sanqing.service.StudentService;
import com.sanqing.service.StudentServiceImpl;
import com.sanqing.util.Page;
import com.sanqing.util.PageUtil;

public class QueryAllStudent extends ActionSupport{
	
	private int currentPage;	
	private StudentService studentService=new StudentServiceImpl();
	
	
	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}


	public String execute () throws Exception{		
		
//		page.setEveryPage(10);
//		page.setCurrentPage(currentPage);
		
		System.out.println("QueryAllStudent:"+currentPage);
		
		int count=studentService.findStudentCount();		
		Page page=PageUtil.createPage(10, count, currentPage);
		
		List<Student> stumsgs=studentService.findAllStudents();
		List<Student> stumsgs2=studentService.findStudentByPage(page);
//		List<Student> stumsgs3=studentService.likeQueryStudentByName("李三", page);
		
		HttpServletRequest request=ServletActionContext.getRequest();
		request.setAttribute("stumsgs", stumsgs2);
		request.setAttribute("page", page);
		
		System.out.println(count);
		System.out.println("stumsgs"+stumsgs.size()+"  "+stumsgs.get(1).getStudentID());
		System.out.println("stumsgs2"+stumsgs2.size()+"  "+stumsgs2.get(1).getStudentID());
//		System.out.println("stumsgs3"+stumsgs3.size()+"  "+stumsgs3.get(1).getStudentID());
		
		return "sucess";
	}
	

}
